<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="__PUBLIC__/admin/css/x-admin.css" media="all">
    </head>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>九宫格抽奖</cite></a>
              <a><cite>抽奖列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
        <div class="x-body">
            <form class="layui-form x-center" action="" style="width:40%" method="post">
              <div class="layui-form-item">
                <div class="layui-input-inline">
                  <input type="text" name="name"  placeholder="请输入手机号" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                </div>
              </div>
            </form>
            <xblock>
                <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
                <span class="x-right" style="line-height:40px">共有数据：{$num} 条</span>
            </xblock>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            <input type="checkbox" name="a" value="">
                        </th>
                        <th>
                            ID
                        </th>
                        <th>
                            抽奖手机
                        </th>
                        <th>
                            奖品名称
                        </th>
                        <th>
                            抽奖时间
                        </th>
                        <th>
                            奖品状态
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($list as $v) { ?>
                    <tr>
                        <td>
                            <input class="son" type="checkbox" value="{$v.id}" name="aa">
                        </td>
                        <td>
                            {$v.id}
                        </td>
                        <td>
                            <?php echo re_phone($v['phone_id']) ?>
                        </td>
                        <td>
                            <?php echo re_lwname($v['num']) ?>
                        </td>
                        <td>
                            <?php echo date('Y-m-d H:i:s',$v['cj_time']) ?>
                        </td>
                        <td>
                            <?php if ($v['is_fafang'] == 1) { ?>
                                <span style="padding: 5px;background: #3ad25a;color: #fff;">已发放</span>
                            <?php }else { ?>
                                <span style="padding: 5px;background: #b1a3a3;color: #fff;">未发放</span>
                            <?php } ?>
                        </td>
                        <td class="td-manage">

                        <?php if ($v['is_fafang'] ==1) { ?>
                            <a href="javascript:;" onclick="is_fafang_no(this,{$v['id']})" class="layui-btn layui-btn-mini layui-btn-danger" style="text-decoration:none">取消发放</a>
                        <?php } else { ?>
                            <a href="javascript:;" onclick="is_fafang_ok(this,{$v['id']})" class="layui-btn layui-btn-mini" style="text-decoration:none">奖品发放</a>
                        <?php } ?>

                            <a title="删除" href="javascript:;" onclick="log_del(this,'{$v['id']}')" 
                            style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
            <style>
                .fenye{ margin-top: 20px;}
                .fenye div a,.fenye div span{display: inline-block;padding: 5px 15px;margin-right: -1px;border: 1px solid #1AA094;}
                .fenye div span{background: #1AA094;color: #fff;}
            </style>
            <div class="fenye">{$page}</div>
        </div>
        <script src="__PUBLIC__/admin/lib/layui/layui.js" charset="utf-8"></script>
        <script src="__PUBLIC__/admin/js/x-layui.js" charset="utf-8"></script>
        <script>
            layui.use(['element','layer'], function(){
                $ = layui.jquery;//jquery
              lement = layui.element();//面包导航
              layer = layui.layer;//弹出层

            //单击全选 单击取消
            $('input[name="a"]').click(function(){  
                        //alert(this.checked);  
                        if($(this).is(':checked')){  
                            $('input[name="aa"]').each(function(){  
                                //此处如果用attr，会出现第三次失效的情况  
                                $(this).prop("checked",true);  
                            });  
                    }else{  
                        $('input[name="aa"]').each(function(){  
                                $(this).removeAttr("checked",false);  
                            });  
                            //$(this).removeAttr("checked");  
                    }  
                          
                }); 
            })

              
            //批量删除提交
             function delAll () {
                layer.confirm('确认要删除吗？',function(index){
                    //捉到所有被选中的，发异步进行删除
                    var arr = new Array();
                    var chenked=$(".son:checked").each(function(){
                       arr.push($(this).val()); 
                    })
                    //data.field.ids = arr;
                    //发异步，把数据提交给php
                    $.ajax({
                        url: "{:U('admin/cj/index_dels')}",//请求地址
                        type: "post",//请求方式
                        dataType: "json",//返回数据类型
                        data: {arr:arr},//发送的参数
                        })
                        .done(function(response) {
                              if(response.error==0){
                                 layer.msg(response.info ,{icon:5});
                              }else{
                                 layer.msg(response.info ,{icon:6});
                                 location.reload();
                              }
                          })
                        .fail(function() {
                            alert("ajxs交互失败");
                        })  

                    return false;  
                });
             }
           
            /*-删除*/
            function log_del(obj,id){
                layer.confirm('确认要删除吗？',function(index){
                    //发异步删除数据
                    id = id;
                    $.ajax({
                        url: "{:U('admin/cj/index_del')}",//请求地址
                        type: "post",//请求方式
                        dataType: "json",//返回数据类型
                        data: {id:id},//发送的参数
                        })
                        .done(function(response) {
                              if(response.error==1){
                                layer.msg(response.info ,{icon:6});
                                $(obj).parents("tr").remove();
                              }else{
                                layer.msg(response.info ,{icon:5});
                              }
                          })
                        .fail(function() {
                            alert("ajxs交互失败");
                        })  
                    return false;
                });
            }

            /*发放*/
            function is_fafang_ok(obj,id){
                layer.confirm('确认要发放吗？',function(index){
                    //发异步删除数据
                    id = id;
                    $.ajax({
                        url: "{:U('admin/cj/is_fafang_ok')}",//请求地址
                        type: "post",//请求方式
                        dataType: "json",//返回数据类型
                        data: {id:id},//发送的参数
                        })
                        .done(function(response) {
                              if(response.error==1){
                                layer.msg(response.info ,{icon:6});
                                location.reload();
                              }else{
                                layer.msg(response.info ,{icon:5});
                              }
                          })
                        .fail(function() {
                            alert("ajxs交互失败");
                        })  
                    return false;
                });
            }
            /*取消*/
            function is_fafang_no(obj,id){
                layer.confirm('确认要取消吗？',function(index){
                    //发异步删除数据
                    id = id;
                    $.ajax({
                        url: "{:U('admin/cj/is_fafang_no')}",//请求地址
                        type: "post",//请求方式
                        dataType: "json",//返回数据类型
                        data: {id:id},//发送的参数
                        })
                        .done(function(response) {
                              if(response.error==1){
                                layer.msg(response.info ,{icon:6});
                                location.reload();
                              }else{
                                layer.msg(response.info ,{icon:5});
                              }
                          })
                        .fail(function() {
                            alert("ajxs交互失败");
                        })  
                    return false;
                });
            }
            </script>
    </body>
</html>